home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0867.dms / q0867.adf / TRAPDOOR.LZH / Rexx / XArc.rexx < prev   
OS/2 REXX Batch file  |  1992-02-12  |  2KB  |  120 lines

  1. /* :ts=2
  2.  *
  3.  *  XArc.rexx
  4.  *
  5.  *  Unpack archive file of any type based on file contents.
  6.  *
  7.  *  Currently supported: ZOO, LHARC, ARC, ZIP, ARJ
  8.  */
  9.  
  10. options failat 10
  11.  
  12. signal on halt
  13. signal on ioerr
  14. signal on break_c
  15.  
  16. CSI     = '9b'x
  17. OFF     = CSI'0m'
  18. BO      = CSI'37m'
  19.  
  20. packer.       = ""
  21. cmd.          = ""
  22.  
  23. packer.arc            = "pkxArc"
  24. cmd.x.arc            = "-e"
  25. cmd.v.arc            = "-v"
  26. cmd.a.arc            = ""
  27.  
  28. packer.zoo            = "Zoo"
  29. cmd.x.zoo            = "e//"
  30. cmd.v.zoo            = "v"
  31. cmd.a.zoo            = "a"
  32.  
  33. /*packer.lharc        = "LHArc -a -x -m"*/
  34. packer.lharc        = "lha -a -x -m"
  35. cmd.x.lharc            = "e"
  36. cmd.v.lharc            = "v"
  37. cmd.a.lharc            = "a"
  38.  
  39. packer.zip            = "unzip"
  40. cmd.x.zip                =    " "
  41. cmd.v.zip                = "-v"
  42. cmd.a.zip            = ""
  43.  
  44. packer.arj            = "unarj"
  45. cmd.x.arj                = "x"
  46. cmd.v.arj                = "l"
  47. cmd.a.arj                = ""
  48.  
  49. ext = "ZOO LZH ARC ZIP ARJ"
  50.  
  51. if arg() = 0 | arg(1) = '?' then call usage
  52.  
  53. parse upper arg option infiles
  54.  
  55.  
  56. select
  57.   when option="V" then com=v
  58.   when option="E" then com=x
  59.   when option="X" then com=x
  60.   when option="A" then com=a
  61.   otherwise call usage
  62. end
  63.  
  64. parse var infiles file infiles
  65.  
  66. ofile = file
  67. do while ~exists(file)
  68.   parse var ext this ext
  69.   if this="" then do
  70.     say BO"Can't find" ofile OFF
  71.     exit 20
  72.   end
  73.   file = ofile"."this
  74. end
  75.  
  76. /* ------- Get type from file content ------- */
  77. if ~open('in', file, 'R') then do
  78.   say BO"Can't open" file OFF
  79.   exit 20
  80. end
  81. buff = readch('in', 8)
  82. call close ('in')
  83.  
  84. select
  85.   when substr(buff, 3, 3) == '-lh'              then type = lharc
  86.   when left(buff, 4)      == 'ZOO '             then type = zoo
  87.   when left(buff, 2)      == 'PK'               then type = zip
  88.     when left(buff, 2)            == '60'x||'ea'x    then type = arj
  89.   when left(buff, 1)      == '1A'x              then type = arc
  90.   otherwise do
  91.     say BO"Cannot handle" file"!"OFF
  92.     exit 20
  93.   end
  94. end
  95.  
  96. say BO"Processing" file "type" type "..."OFF
  97. if cmd.com.type=="" then do
  98.     say BO"Can't do that"OFF
  99.     exit 20
  100. end
  101.  
  102. Address Command packer.type cmd.com.type file infiles
  103. exit RC
  104.  
  105. /* ----------------------------------------------------------------------- */
  106. * Error Handling */
  107. halt:
  108. ioerr:
  109. break_c:
  110. exit 10
  111.  
  112. /* ----------------------------------------------------------------------- */
  113. usage:
  114.     say "Usage: XArc command filename [filename..]"
  115.     say
  116.     say "    E,X   extract files"
  117.     say "    V     list archive contents"
  118.     say "    A     add files to archive"
  119.     exit 0
  120.